package com.horoscope.astrology.zodiac.signs.free.adapter

import android.content.Context
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.horoscope.astrology.zodiac.signs.free.R

class SettingAdapter(
    private val context: Context,
    private val dataLists: Array<String>?,
    private val imageLists: IntArray,
    private val versionNum: String
) : BaseAdapter() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return MyViewHolder(
            LayoutInflater.from(context).inflate(R.layout.fragment_recy_item, parent, false)
        )
    }

    override fun getItemCount(): Int {
        return dataLists?.size ?: 0
    }

    override fun onBindViewHolder(viewHolder: RecyclerView.ViewHolder, i: Int) {
        when (viewHolder) {
            is MyViewHolder -> {
                val drawable: Drawable? =
                    ContextCompat.getDrawable(context, R.drawable.ic_chevron_right_black_24dp)
                drawable?.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)

                viewHolder.itemView.tag = i
                viewHolder.text.text = dataLists!![i]
                viewHolder.imageViewLeft.setImageResource(imageLists[i])
                if (i < 4) {
                    viewHolder.textViewRight.setCompoundDrawables(null, null, drawable, null)
                } else {
                    viewHolder.textViewRight.text = versionNum
                    viewHolder.textViewRight.setPadding(0, 0, 20, 0)
                }
                viewHolder.itemView.setOnClickListener { v ->
                    mOnItemClickedListener!!.onItemClick(v, i,"")
                }
            }
        }
    }

    class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val text: TextView = itemView.findViewById(R.id.tv_text)
        val imageViewLeft: ImageView = itemView.findViewById(R.id.img_left)
        val textViewRight: TextView = itemView.findViewById(R.id.tv_right)
    }



}